package zm.irc.cmd;

import org.apache.log4j.Logger;
import zm.irc.client.IrcClient;
import zm.irc.ioc.ApplicationContext;
import zm.irc.message.receive.IrcReceiveCmdMessage;

import zm.irc.ioc.annotation.AutoWired;
import zm.irc.ioc.annotation.Service;

@Service
public class CmdExecutor {
    private static final Logger log = Logger.getLogger(CmdExecutor.class);

    @AutoWired
    private ApplicationContext context;
    
    /**
     * return true: Continue process pipe-line
     * return false: Stop process pipe-line
     * @param cmd
     * @return
     */
    public boolean executor(IrcReceiveCmdMessage cmd, IrcClient client){

        if(cmd == null){
            return true;
        }
        String cmdName = cmd.getCmdName();

        IrcChatMsgCmd ircChatMsgCmd = this.context.getBeanById(cmdName,IrcChatMsgCmd.class);

        if(ircChatMsgCmd != null){
            return ircChatMsgCmd.execute(cmd,client);
        }else{
            log.error("Unsupport command:" + cmdName);
            return true;
        }


    }
}
